<template>
  <div class="base-panels">
    <Row type="flex">
      <Col flex="600px"> <h2 class="title2">参建人员 <i>{{ config.page.total }}</i></h2></Col>
      <Col flex="550px">

      </Col>
    </Row>

    <Table
        :columns="config.columns"
        :row-key="record => record.staffId"
        :data-source="config.list"
        :pagination="config.page"
        :loading="config.loading"
        @change="(pagination)=> changeHandler(pagination, config)"
        bordered
    >
      <template #indexSlot="{ index }">{{(config.page.current-1)*10+index+1}}</template>
      <template #name="{ text, record }">
        <router-link target="_blank" :to="{ path: `/staff/${record.staffId}` }" class="blue" >
          {{ text }}
        </router-link>
      </template>
    </Table>
  </div>

</template>

<script lang="ts">
import {defineComponent, inject, onMounted, reactive, toRefs} from 'vue';
import {Row, Col, Table } from 'ant-design-vue';
import { getActivityPersonApi  } from '/@/api/activity';
import { parseTime } from '/@/utils';

const columns = [
  { title: '序号', dataIndex: 'index', width: 70, align: 'center', slots: ({ customRender: 'indexSlot' }) },
  { title: '担任角色', dataIndex: 'staffRoleType',width: 150},
  { title: '人员姓名', dataIndex: 'staffName', width: 120 , slots: ({ customRender: 'name' })},
  { title: '身份证号', dataIndex: 'staffCard' ,width: 230},
  { title: '证书类型及专业', dataIndex: 'staffTaskName', width: 240 }
]

export default defineComponent({
  components: {
    Table , Row, Col
  },
  setup() {
    const activityId = inject('activityId') as string;


    const config = reactive({
      columns: columns,
      list: [],
      loading: false,
      page: {
        total: 0,
        current: 1,
        pageSize:999
      }
    })

    const changeHandler = ( config) => {
      let { loading, list, page } = toRefs(config);
      loading.value = true;
      getActivityPersonApi( { activityId   }).then( ({success,data,total}) => {
        if(success){
          list.value = data;
          loading.value = false;
          page.value.total = total;
        }
      })
    }

    const init = () => {
      changeHandler(config);
    }
    onMounted(init)
    return {
      config, changeHandler  , parseTime
    }
  },
})
</script>

<style lang="less" scoped>
.base-panels{
  padding: 0 20px 50px;
}

.ant-col{
  padding-top: 16px;
  margin-bottom: 8px;
}

.ant-select ,.ant-btn{
  width: 100%;
}

.ant-col.text-right{
  padding-right: 0 !important;
}

</style>
